package com.objectproject.main.service.subsystem;

import java.util.ArrayList;
import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.objectproject.main.dao.MyLocaleDAOImpl;
import com.objectproject.main.model.MyLocale;

@Service
public class MyLocaleResolver {
	
	
	@Autowired
	MyLocaleDAOImpl myLocaleDAOImpl;
	
	public Locale resolveLocale(MyLocale myLocale){
		return new Locale(myLocale.getLanguageString(), myLocale.getCountryString());
	}
	
	public Locale resolveLocale(int localeId){
		MyLocale myLocale = myLocaleDAOImpl.getMyLocaleById(localeId);
		return new Locale(myLocale.getLanguageString(), myLocale.getCountryString());
	}
	
	public int resolveLocaleId(Locale locale){
		MyLocale myLocale = myLocaleDAOImpl.getMyLocaleByString(locale.toString());
		return myLocale.getLocaleId();
	}

	public int resolveLocaleId(MyLocale myLocale){
		return myLocale.getLocaleId();
	}
	
	public boolean isAvailable(Locale locale){
		ArrayList<MyLocale> myLocales = myLocaleDAOImpl.getAllValidMyLocales();
		for(int i = 0 ; i < myLocales.size() ; i++){
			if(myLocales.get(i).toString().equals(locale.toString()))
				return true;
		}
		return false;
	}
	
	public boolean isAvailable(MyLocale myLocale){
		ArrayList<MyLocale> myLocales = myLocaleDAOImpl.getAllValidMyLocales();
		for(int i = 0 ; i < myLocales.size() ; i++){
			if(myLocales.contains(myLocale)){
				return true;
			}
		}
		return false;
	}
	
	public boolean isAvailable(int localeId){
		ArrayList<MyLocale> myLocales = myLocaleDAOImpl.getAllValidMyLocales();
		for(int i = 0 ; i < myLocales.size() ; i++){
			if(myLocales.get(i).getLocaleId() == localeId)
				return true;
		}
		return false;
	}
}
